<?php
include_once(dirname(__FILE__)."/../../inc/common.php");
$method = isset($_GET["method"])?$_GET["method"]:"";

if($method=="tag"){
	$more = isset($_GET["more"])?$_GET["more"]:1;
	?>
	<div id="winwrapper" class="winwrapper">
		<!-- begin:搜索区 -->
		<div class="searchbar" id ="searchbar" style="height: 22px;">
			<form id="tagPickerSchForm" action="" method="post">
				<div class="base_condition">
					<label for="tagId">关键字:</label>
					<input type="text" name="tagName" id="tagId" class="text" id="payeeName" maxlength="20" value=""/>
					<a id="searchBtn"  title="查询"  href="javascript:fGoto();" onclick="TagPicker.search(undefined);"><span><img src="/images/icons/advsearch.gif" align="absmiddle"/>查询</span></a>
					<a id="addBtn"  title="标签管理" href="/setting/index.php?subModule=Tag"><span><img src="/images/icons/add.gif" align="absmiddle"/>标签管理</span></a>

					<?php
					if($more) {
					?>
					<input type="hidden" value="1" name="more" id="more"/>
					<input id="searchBtn" class="button" type="button" value="确定" onclick="TagPicker.finished(this);" style="margin-left: 30px;"/>
					<?php
					}
					?>

				</div>
			</form>
		</div>
		<?php
		if($more) {
		?>
			<div class="select_result">

				已选择:<input type="hidden" value="" name="select_tag_ids" id="select_tag_ids"/>
				<span id="select_tag" class="select_tag"></span>
	  <span style="text-align: right;margin-left: 8px;">
	  </span>

			</div>
		<?php
		}
		?>
		<!-- end:搜索区 -->
		<!-- begin:-------主数据区 -------------------->
		<div id="tagPickerDataView" class="data">

		</div>
		<!--end: ----------主数据区----------------->
	</div>
	<?php
}else if($method=="tagQry"){
	$tagName = isset($_POST["tagName"])?$_POST["tagName"]:"";
	$pageSize = 200;
	$showInvisible = isset($_GET["showInvisible"]) && ($_GET["showInvisible"]==1)?1:0;
	$curPage = isset($_GET["curPage"])?$_GET["curPage"]:1;
	$more = isset($_GET["more"])?$_GET["more"]:1;
	$tallyTagClass = new tally_tag();
	$tagList = $tallyTagClass->findTagByAccountId($userId, $tagName, $showInvisible, ($curPage-1)*$pageSize, $pageSize);
	$total = $tallyTagClass->countTagByAccountId($userId, $tagName, $showInvisible);
	$nownum = $tagList?count($tagList):0;
	?>
	<div>
		<table width="100%" align="center" class="listtable" cellpadding="0" cellspacing="1" >
			<tr>
				<td>
					<?php
					foreach($tagList as $tag){
						if($more){
							?>
							<span style="margin: 0px 3px 10px 3px;font-size: 15px;"><a href="#" title="<?php echo $tag["name"]?>" onclick="TagPicker.pickMore(this, {tagId:'<?php echo $tag["id"]?>',tagName:'<?php echo $tag["name"]?>'});"><?php echo $tag["name"]?></a></span>
							<?php
						}else{
							?>
							<span style="margin: 0px 3px 10px 3px;font-size: 15px;"><a href="#" title="<?php echo $tag["name"]?>" onclick="TagPicker.pick({tagId:'<?php echo $tag["id"]?>',tagName:'<?php echo $tag["name"]?>'});CM.close(this);"><?php echo $tag["name"]?></a></span>
							<?php
						}
				   } ?>
				</td>
			</tr>
		</table>

	</div>
	<!--end:数据列表区-------------------------------------------------------------------------------------------------->
	<?php
}else if($method=="tallyTag"){
	?>
	<div id="winwrapper" class="winwrapper">
		<!-- begin:搜索区 -->
		<div class="searchbar" id ="searchbar" style="height: 22px;">
			<form id="tagPickerSchForm" action="" method="post">
				<div class="base_condition">
					<label for="tagId">关键字:</label>
					<input type="text" name="tagName" id="tagId" class="text" id="payeeName" maxlength="20" value=""/>
					<a id="searchBtn"  title="查询"  href="javascript:fGoto();" onclick="TallyTagPicker.search(1);"><span><img src="../images/icons/advsearch.gif" align="absmiddle"/>查询</span></a>
					<a id="addBtn"  title="标签管理" href="../setting/index.php?subModule=Tag"><span><img src="../images/icons/add.gif" align="absmiddle"/>标签管理</span></a>

					<input type="hidden" value="1" name="more" id="more"/>
					<input id="searchBtn" class="button" type="button" value="确定" onclick="TallyTagPicker.finished(this);" style="margin-left: 30px;"/>

				</div>
			</form>
		</div>

		<div class="select_result">

			已选择:
			<span id="select_tag" class="select_tag"></span>
			<input type="hidden" id="select_tagIds" value="" >
	  <span style="text-align: right;margin-left: 8px;">
	  </span>

		</div>

		<!-- end:搜索区 -->
		<!-- begin:-------主数据区 -------------------->
		<div id="tagPickerDataView" class="data">

		</div>
		<!--end: ----------主数据区----------------->
	</div>
	<?php
}else if($method=="tallyTagQry"){
	$tagName = isset($_POST["tagName"])?$_POST["tagName"]:"";
	$pageSize = 200;
	$showInvisible = isset($_GET["showInvisible"]) && ($_GET["showInvisible"]==1)?1:0;
	$curPage = isset($_GET["curPage"])?$_GET["curPage"]:1;
	$tallyTagClass = new tally_tag();
	$tagList = $tallyTagClass->findTagByAccountId($userId, $tagName, $showInvisible, ($curPage-1)*$pageSize, $pageSize);
	$total = $tallyTagClass->countTagByAccountId($userId, $tagName, $showInvisible);
	$nownum = $tagList?count($tagList):0;
	?>
	<div>
		<table width="100%" align="center" class="listtable" cellpadding="0" cellspacing="1" >
			<tr>
				<td>
					<?php
					foreach($tagList as $tag){
						?>
						<span style="margin: 0px 3px 10px 3px;font-size: 15px;"><a href="#" title="<?php echo $tag["name"]?>" onclick="TallyTagPicker.pickMore(this, {tagId:'<?php echo $tag["id"]?>',tagName:'<?php echo $tag["name"]?>'});"><?php echo $tag["name"]?></a></span>
					<?php   } ?>
				</td>
			</tr>

			<tr class="footer" valign="bottom">
				<td>
					<span class=pagebar><?php echo isspage($total,$nownum,$pageSize,$curPage); ?></span>
				</td></tr>
		</table>

	</div>
	<!--end:数据列表区-------------------------------------------------------------------------------------------------->
	<?php
}else if($method=="category"){
	$inOut = 0;
	$showInvisible = 0;
	$oids = isset($_GET["oids"])?$_GET["oids"]:"";
	$oidList = explode(",", $oids);
	$tallyFlowTypeClass = new tally_flowType();
	$flowTypeList = $tallyFlowTypeClass->findAllFlowType($userId);
	?>
	<div id="winwrapper" class="winwrapper" style="height: auto;overflow-y:auto; ">
		<div class="searchbar" id ="searchbar" style="text-align: right;">
			<input id="searchBtn" class="button" type="button" value="所有收入" onclick="CategoryPicker.pickFlowType(3);"/>
			<input id="searchBtn" class="button" type="button" value="所有支出" onclick="CategoryPicker.pickFlowType(4);"/>
			<input id="searchBtn" class="button" type="button" value="确定" onclick="CategoryPicker.pick(this);	CM.close(this);"/>
		</div>

		<!-- end:搜索区 -->
		<!-- begin:-------主数据区 -------------------->
		<form id="editForm" name="editForm">
			<table id="categoryPickerList" class="listtable" cellpadding="0" cellspacing="1">
				<thead>
				<tr>
					<th width="20"></th>
					<th width="30%">名称</th>
					<th width="30%">类别</th>
					<th width="30%">备注</th>
				</tr>
				</thead>
				<tbody>

				<?php
				foreach($flowTypeList as $flowType) {
					?>
					<tr>
						<td><input type="checkbox" name="categoryId" id="<?php echo $flowType["id"]?>" value="<?php echo $flowType["id"]?>" flowType="<?php echo $flowType["flowType"] ?>" <?php echo in_array($flowType["id"], $oidList)?'checked="checked"':''; ?> /></td>
						<td class="char" onclick="CM.selectBox(this);">
							<input type="hidden" name="categoryName" value="<?php echo $flowType["name"]?>">
							<?php echo $flowType["name"]?>
						</td>
						<td>
							<?php echo tally_flow::$INOUT_DESC[$flowType["flowType"]]?>

						</td>
						<td></td>
					</tr>
					<?php
				}
				?>

				</tbody>
			</table>
		</form>

		<!--end: ----------主数据区----------------->
	</div>
	<?php
}
?>
